var testPlan_left = {
		insertTestPlan : function(name){
			var params = {
					"name":name,
					"state":1
			};
			$.ajax({
    	        type : "post",
    	        url :path+'/testCaseController/insertTestPlan',//找到controller里相应的方法
    	        data : params, //把数组的值赋给data，把上面的param改为data,这里就能直接去掉
    	        dataType : "json",//根据数据类型选择text、jason等
    	        success : function(data) { 
    	        	if(data.result == true){
    	        		testPlan_left.listTestPlan();
        	        	var testplanId = data.msg;
        	        	$('#testplanId').val(testplanId);
        	        	testPlan_left.testplanIdChange();
		        		parent.layer.closeAll();
		        		parent.toast.success('操作成功！','成功提示');
		        	}else{
		        		toast.error('操作失败！','失败提示');
		        	}
    	        	
    	        }
    	       });
		},
		insertTestSuite : function(name){
			var params = {
					"parentId":nodeId,
					"name":name,
					"state":0
			};
			$.ajax({
    	        type : "post",
    	        url :path+'/testCaseController/insertTestSuite',//找到controller里相应的方法
    	        data : params, //把数组的值赋给data，把上面的param改为data,这里就能直接去掉
    	        dataType : "json",//根据数据类型选择text、jason等
    	        success : function(data) { 
    	        	if(data.result == true){
    	        		testPlan_left.testplanIdChange();
		        		parent.layer.closeAll();
		        		parent.toast.success('操作成功！','成功提示');
		        	}else{
		        		toast.error('操作失败！','失败提示');
		        	}
    	        }
    	       });
			
		},
		listTestPlan : function(){
			
			$.ajax({
			    type : "get",
			    async: false,//必须同步
			    url : path+'/testCaseController/listTestPlan?projectId='+currentProjectId,//找到controller里相应的方法
			    success : function(dataList) {
			    	//加载计划下拉列表
    		    	$("#testplanId").html("");
    		    	$(dataList).each(function(index,data){
    		    		$("#testplanId").append("<option value="+data.id+">"+data.name+"</option>");
    				});
    		    	if (testplanId != null && testplanId != '') {
    		    		$("#testplanId").val(testplanId);
    		    	}
			    }
			   });
		},
		testplanIdChange : function(type){
			var testplanId = $('#testplanId option:selected').val();
			if(type == "change"){
				$('#resultId').val("");
				$('#stateId').val("");
				$('#moduleId').val("");
				$('#assignId').val("");
				$('#authorId').val("");
				paramResult = "";
				state = "";
				moduleId = "";
				assignId = "";
				authorId = "";
				
			}
			
			testPlan_left.listTreeOnTestPlan(testplanId);
			testPlan_left.initZtree();
			var params={
		            silent: true,
		            url:path+"/testCaseController/listTestCaseWithResult?nodeId="+nodeId
							+"&&showAll="+showAll+"&&result="+paramResult+"&&state="+state
							+"&&moduleId="+moduleId+"&&assignId="+assignId+"&&authorId="+authorId
		    };
			$('#testPlanTable').bootstrapTable('refresh',params);
			testPlan_list.listTestCaseWithResultPramList();
			testPlan_grid.initTestCaseGrid();
			
		},
		listTreeOnTestPlan : function(testplanId){
				$.ajax({
				    type : "get",
				    async: false,//必须同步
				    url : path+'/testCaseController/listTestPlanAndSuiteByTestPlanId?testplanId='+testplanId,//找到controller里相应的方法
				    
				    success : function(dataList) {
				    	zNodes = [];
				    	$(dataList).each(function(index,data){
				    		zNodes.push({ id:data.id, pId:data.parentId, name:data.name,nodeTypeId:data.nodeTypeId,listTree_nodeId:data.nodeId});
				    	});
				    }
				   });
		},
		initZtree : function(){
			$.fn.zTree.init($("#treeDemo"), setting, zNodes);
			$("#expandAllBtn").bind("click", {type:"expandAll"}, testPlan_left.expandNode);
			$("#collapseAllBtn").bind("click", {type:"collapseAll"}, testPlan_left.expandNode);
			
			zTree = $.fn.zTree.getZTreeObj("treeDemo");
			rMenu = $("#rMenu");
			zTree.expandAll(true);
			var nodes = zTree.getNodes();
			zTree.selectNode(nodes[0]);
			nodeId = nodes[0].id;
			nodeTypeId = nodes[0].nodeTypeId;
			listTree_nodeId = nodes[0].listTree_nodeId;
		},
		//用于捕获节点被点击的事件回调函数
		zTreeOnClick : function(event, treeId, treeNode){
			nodeTypeId = treeNode.nodeTypeId;
			nodeId = treeNode.id;
			nodeName = treeNode.name;
			listTree_nodeId = treeNode.listTree_nodeId;
			$('#resultId').val("");
			$('#stateId').val("");
			$('#moduleId').val("");
			$('#assignId').val("");
			$('#authorId').val("");
			paramResult = "";
			state = "";
			moduleId = "";
			assignId = "";
			authorId = "";
			var params={
		            silent: true,
		            url:path+"/testCaseController/listTestCaseWithResult?nodeId="+nodeId
							+"&&showAll="+showAll+"&&result="+paramResult+"&&state="+state
							+"&&moduleId="+moduleId+"&&assignId="+assignId+"&&authorId="+authorId,
					ajaxOptions: {
						beforeSend:function(xmlHttp){
						},
					    complete: function (jqXHR) {
					    }
		             }
					
		    };
			$('#testPlanTable').bootstrapTable('refreshOptions',params);
			testPlan_grid.initTestCaseGrid();
			testPlan_list.listTestCaseWithResultPramList();
			
		},
		expandNode : function(e){
			var zTree = $.fn.zTree.getZTreeObj("treeDemo"),
			type = e.data.type,
			nodes = zTree.getSelectedNodes();
			if (type.indexOf("All")<0 && nodes.length == 0) {
				alert("请先选择一个父节点");
			}

			if (type == "expandAll") {
				zTree.expandAll(true);
			} else if (type == "collapseAll") {
				zTree.expandAll(false);
			} else {
				var callbackFlag = $("#callbackTrigger").attr("checked");
				for (var i=0, l=nodes.length; i<l; i++) {
					zTree.setting.view.fontCss = {};
					if (type == "expand") {
						zTree.testPlan_left.expandNode(nodes[i], true, null, null, callbackFlag);
					} else if (type == "collapse") {
						zTree.testPlan_left.expandNode(nodes[i], false, null, null, callbackFlag);
					} else if (type == "toggle") {
						zTree.testPlan_left.expandNode(nodes[i], null, null, null, callbackFlag);
					} else if (type == "expandSon") {
						zTree.testPlan_left.expandNode(nodes[i], true, true, null, callbackFlag);
					} else if (type == "collapseSon") {
						zTree.testPlan_left.expandNode(nodes[i], false, true, null, callbackFlag);
					}
				}
			}
			
		},
		//左侧树节点拖拽事件
		onDrop : function(event, treeId, treeNodes, targetNode, moveType, isCopy){
			layer.confirm('确定要移动该节点至此位置吗？', {icon: 3, title:'<span class="glyphicon glyphicon-th-large"></span>&nbsp;提示'}, function(){
				var hierarchyId = treeNodes[0].id;
				var parentId = "";
				if(targetNode != null){
					if(moveType == "inner"){
						parentId = targetNode.id;
					}else if(moveType == "prev" || moveType == "next"){
						parentId = targetNode.pId;
					}
					$.ajax({
		    	        type : "post",
		    	        url : path+'/testCaseController/moveTestSuite',//找到controller里相应的方法
		    	        data : {"hierarchyId":hierarchyId,"parentId":parentId}, //把数组的值赋给data，把上面的param改为data,这里就能直接去掉
		    	        dataType : "json",//根据数据类型选择text、jason等
		    	        success : function(data) { 
		    	        	if(data.result == true){
				        		toast.success('操作成功！','成功提示');
				        	}else{
				        		toast.error('操作失败！','失败提示');
				        	}
		    	        }
		    	       });
				}else{
					toast.info ('目标节点为空，不允许拖拽！','信息提示'); 
				}
				layer.closeAll();
			},function(){
				testPlan_left.testplanIdChange();
			});
		},
		//禁止将节点拖拽成为根节点
		beforeDrop : function(treeId, treeNodes, targetNode, moveType){
			 return !(targetNode == null || (moveType != "inner" && !targetNode.parentTId));
		},
		
		/* =======节点后的增删改操作开始============== */
		
		//用于当鼠标移出节点时，隐藏用户自定义控件
		removeHoverDom : function(treeId, treeNode){
			$("#addBtn_"+treeNode.tId).unbind().remove();
			
		},
		//判断是否允许编辑（节点后编辑操作以及右键重命名操作共用事件）
		beforeEditName : function(treeId, treeNode){
			if(treeNode != null){
				var zTree = $.fn.zTree.getZTreeObj("treeDemo");
				zTree.selectNode(treeNode);
				zTree.editName(treeNode);
				return false;
			}else{
				testPlan_left.hideRMenu();
				zTree = $.fn.zTree.getZTreeObj("treeDemo");
				var treeNode = zTree.getSelectedNodes()[0];
				var zTree = $.fn.zTree.getZTreeObj("treeDemo");
				zTree.selectNode(treeNode);
				zTree.editName(treeNode);
				return false;
			}
		},
		//删除节点之后的回调
		onRemove : function(e, treeId, treeNode){
			layer.confirm('确定要删除该节点吗？', {icon: 3, title:'<span class="glyphicon glyphicon-th-large"></span>&nbsp;提示'}, function(){
				 testPlan_left.deleteTreeNode(treeNode.nodeTypeId,treeNode.id);
				 layer.closeAll();
			},function(){
				testPlan_left.initZtree();
			});
			
		},
		//用于捕获节点编辑名称结束（Input 失去焦点 或 按下 Enter 键）之后，更新节点名称数据之前的事件回调函数，
		//并且根据返回值确定是否允许更改名称的操作
		beforeRename : function(treeId, treeNode, newName, isCancel){
			if(treeNode.name == newName){
				var treeObj = $.fn.zTree.getZTreeObj("treeDemo");
				treeObj.setEditable(false);
				treeObj.setEditable(true);
				return false;
			}else{
				if (newName.length == 0) {
					setTimeout(function() {
						var zTree = $.fn.zTree.getZTreeObj("treeDemo");
						zTree.cancelEditName();
						toast.info ('节点名称不能为空！','信息提示'); 
					}, 0);
					return false;
				}else if(newName.length > 100){
					setTimeout(function() {
						var zTree = $.fn.zTree.getZTreeObj("treeDemo");
						zTree.cancelEditName();
						toast.info ('节点名称不能超过100个字符！','信息提示');  
					}, 0);
					return false;
				}
				return true;
			}
		},
		//用于捕获节点编辑名称结束之后的事件回调函数。
		onRename : function(e, treeId, treeNode, isCancel){
			if(treeNode.nodeTypeId == 1){
				var params = {
						"testplanId":treeNode.listTree_nodeId,
						"name":treeNode.name
				};
				$.ajax({
	    	        type : "post",
	    	        url :path+'/testCaseController/updateTestPlan',//找到controller里相应的方法
	    	        data : params, //把数组的值赋给data，把上面的param改为data,这里就能直接去掉
	    	        dataType : "json",//根据数据类型选择text、jason等
	    	        success : function(data) { 
	    	        	if(data.result == true){
	    	        		var selectedTestplanId = $('#testplanId option:selected').val();
	    	        		testPlan_left.listTestPlan();
	    	        		$('#testplanId ').val(selectedTestplanId);
			        		toast.success('操作成功！','成功提示');
			        	}else{
			        		toast.error('操作失败！','失败提示');
			        	}
	    	        }
	    	       });
			}else if(treeNode.nodeTypeId == 2){
				var params = {
						"testsuiteId":treeNode.listTree_nodeId,
						"name":treeNode.name
				};
				$.ajax({
	    	        type : "post",
	    	        url :path+'/testCaseController/updateTestSuite',//找到controller里相应的方法
	    	        data : params, //把数组的值赋给data，把上面的param改为data,这里就能直接去掉
	    	        dataType : "json",//根据数据类型选择text、jason等
	    	        success : function(data) { 
	    	        	if(data.result == true){
			        		layer.closeAll();
			        		toast.success('操作成功！','成功提示');
			        	}else{
			        		toast.error('操作失败！','失败提示');
			        	}
	    	        }
	    	       });
			}
		},
		/* =======节点后的增删改操作结束============== */
		
		/* =======右键增删改操作开始============== */
		//用于捕获 zTree 上鼠标右键点击之后的事件回调函数
		onRightClick : function(event, treeId, treeNode){
			nodeId = treeNode.id;
			nodeTypeId = treeNode.nodeTypeId;
			if(treeNode.nodeTypeId == 1){
				$("#m_open").html('<span class="icon icon-open"></span>&nbsp;&nbsp;打开测试计划');
			}else if(treeNode.nodeTypeId == 2){
				$("#m_open").html('<span class="icon icon-open"></span>&nbsp;&nbsp;打开测试套件');
			}
			if (!treeNode && event.target.tagName.toLowerCase() != "button" && $(event.target).parents("a").length == 0) {
				zTree.cancelSelectedNode();
				testPlan_left.showRMenu("root", event.clientX, event.clientY);
			} else if (treeNode && !treeNode.noR) {
				zTree.selectNode(treeNode);
				testPlan_left.showRMenu("node", event.clientX, event.clientY);
			}
		},
		//显示菜单
		showRMenu : function(type, x, y){
			$("#rMenu ul").show();
			if (type=="root") {
				$("#m_del").hide();
				$("#m_rename").hide();
				$("#m_open").hide();
			} else {
				$("#m_del").show();
				$("#m_rename").show();
				$("#m_open").show();
			}

            y += document.body.scrollTop;
            x += document.body.scrollLeft;
            rMenu.css({"top":y+"px", "left":x+"px", "visibility":"visible"});
			$("body").bind("mousedown", testPlan_left.onBodyMouseDown);
		},
		//隐藏菜单
		hideRMenu : function(){
			if (rMenu) rMenu.css({"visibility": "hidden"});
			$("body").unbind("mousedown", testPlan_left.onBodyMouseDown);
		},
		//当鼠标点击事件不在菜单中时隐藏菜单
		onBodyMouseDown : function(event){
			if (!(event.target.id == "rMenu" || $(event.target).parents("#rMenu").length>0)) {
				rMenu.css({"visibility" : "hidden"});
			}
		},
		//右键菜单中新建触发事件
		addTreeNode : function(){
			testPlan_left.hideRMenu();
			addTestPlanOrSuit(1);
		},
		//右键菜单中删除触发事件
		removeTreeNode : function(){
			testPlan_left.hideRMenu();
			var nodes = zTree.getSelectedNodes();
			if (nodes && nodes.length>0) {
				if (nodes[0].children && nodes[0].children.length > 0) {
					layer.confirm('您要删除的节点是父节点,此操作将删除此节点下的所有子节点,确定要删除吗？', {icon: 3, title:'<span class="glyphicon glyphicon-th-large"></span>&nbsp;提示'}, function(){
						 zTree.removeNode(nodes[0]);
						 testPlan_left.deleteTreeNode(nodeTypeId,nodeId);
						 layer.closeAll();
					});
				} else {
					layer.confirm('确定要删除此节点吗？', {icon: 3, title:'<span class="glyphicon glyphicon-th-large"></span>&nbsp;提示'}, function(){
						zTree.removeNode(nodes[0]);
						testPlan_left.deleteTreeNode(nodeTypeId,nodeId);
						 layer.closeAll();
					});
				}
			}
		},
		//测试计划处删除左侧树节点
		deleteTreeNode : function(nodeTypeId,nodeId){
			var params = {
					"nodeTypeId" : nodeTypeId,
					"hierarchyId" : nodeId
			};
			$.ajax({
    	        type : "post",
    	        url :path+'/testCaseController/deleteTreeNode',//找到controller里相应的方法
    	        data : params, //把数组的值赋给data，把上面的param改为data,这里就能直接去掉
    	        dataType : "json",//根据数据类型选择text、jason等
    	        success : function(data) { 
    	        	if(data.result == true){
    	        		if(nodeTypeId == 1){
    	        			testPlan_left.listTestPlan();
    	        			testPlan_left.testplanIdChange();
    	        		}
    	        		toast.success('操作成功！','成功提示');
    	        	}else{
    	        		toast.error('操作失败！','失败提示');
    	        	}
    	        }
    	       });
		}
		/* =======右键增删改操作结束============== */
};
var testPlan_list = {
		listTestCaseWithResultPramList: function(){
			$.ajax({
			    type : "get",
			    async: true,
			    url : path+"/testCaseController/listTestCaseWithResultPramList?nodeId="+nodeId
						+"&&showAll="+showAll+"&&result="+paramResult+"&&state="+state
						+"&&moduleId="+moduleId+"&&assignId="+assignId+"&&authorId="+authorId,//找到controller里相应的方法
				beforeSend:function(xmlHttp){
				},
			    complete: function (jqXHR) {
			    },
			    success : function(dataMap) {
			    	//模块列表
			    	var moduleList = dataMap.module;
			    	$("#moduleId").html("<option value=''>全部</option>");
    		    	$(moduleList).each(function(index,module){
    		    		$("#moduleId").append("<option value="+module.moduleId+">"+module.moduleNm+"</option>");
    				});
			    	
    		    	//指派人列表
			    	var assignerList = dataMap.assigner;
			    	$("#assignId").html("<option value=''>全部</option>");
    		    	$(assignerList).each(function(index,assigner){
    		    		$("#assignId").append("<option value="+assigner.userId+">"+assigner.userName+"</option>");
    				});	
			    	
			    	//创建人列表
			    	var authorList = dataMap.author;
			    	$("#authorId").html("<option value=''>全部</option>");
    		    	$(authorList).each(function(index,author){
    		    		$("#authorId").append("<option value="+author.userId+">"+author.userName+"</option>");
    				});
			    }
			   });
		},
		resultOnchange : function(){
			paramResult = $('#resultId option:selected').val();
			var params={
		            silent: true,
		            url:path+"/testCaseController/listTestCaseWithResult?nodeId="+nodeId
							+"&&showAll="+showAll+"&&result="+paramResult+"&&state="+state
							+"&&moduleId="+moduleId+"&&assignId="+assignId+"&&authorId="+authorId
		    };
			$('#testPlanTable').bootstrapTable('refresh',params);
		},
		stateOnchange : function(){
			state = $('#stateId option:selected').val();
			var params={
		            silent: true,
		            url:path+"/testCaseController/listTestCaseWithResult?nodeId="+nodeId
							+"&&showAll="+showAll+"&&result="+paramResult+"&&state="+state
							+"&&moduleId="+moduleId+"&&assignId="+assignId+"&&authorId="+authorId
		    };
			$('#testPlanTable').bootstrapTable('refresh',params);
		},
		moduleOnchange : function(){
			moduleId = $('#moduleId option:selected').val();
			var params={
		            silent: true,
		            url:path+"/testCaseController/listTestCaseWithResult?nodeId="+nodeId
							+"&&showAll="+showAll+"&&result="+paramResult+"&&state="+state
							+"&&moduleId="+moduleId+"&&assignId="+assignId+"&&authorId="+authorId
		    };
			$('#testPlanTable').bootstrapTable('refresh',params);
		},
		assignerOnchange : function(){
			assignId = $('#assignId option:selected').val();
			var params={
		            silent: true,
		            url:path+"/testCaseController/listTestCaseWithResult?nodeId="+nodeId
							+"&&showAll="+showAll+"&&result="+paramResult+"&&state="+state
							+"&&moduleId="+moduleId+"&&assignId="+assignId+"&&authorId="+authorId
		    };
			$('#testPlanTable').bootstrapTable('refresh',params);
		},
		authorOnchange : function(){
			authorId = $('#authorId option:selected').val();
			var params={
		            silent: true,
		            url:path+"/testCaseController/listTestCaseWithResult?nodeId="+nodeId
							+"&&showAll="+showAll+"&&result="+paramResult+"&&state="+state
							+"&&moduleId="+moduleId+"&&assignId="+assignId+"&&authorId="+authorId
		    };
			$('#testPlanTable').bootstrapTable('refresh',params);
		},
		//测试计划移除用例
		removeTestCase : function(index){
			setTimeout(function() {
				$(".fixed-table-container tbody tr[data-index='"+index+"']").addClass("selected");
			}, 50);
			 var rowData = $("#testPlanTable").bootstrapTable('getData')[index];
			 var testsuiteId = rowData.parentId;
			 var testcaseIds = rowData.testcaseId;
			 layer.confirm('确定要删除该信息吗？', {icon: 3, title:'<span class="glyphicon glyphicon-th-large"></span>&nbsp;提示'}, function(){
				 $.ajax({
		    	        type : "post",
		    	        url : path+'/testCaseController/removeTestCase',//找到controller里相应的方法
		    	        data : {"testsuiteId":testsuiteId,"testcaseIds":testcaseIds}, //把数组的值赋给data，把上面的param改为data,这里就能直接去掉
		    	        dataType : "json",//根据数据类型选择text、jason等
		    	        success : function(data) { 
		    	        	if(data.result == true){
		    	        		var params={
			    			            silent: true,
			    			            url:path+"/testCaseController/listTestCaseWithResult?nodeId="+nodeId
			    								+"&&showAll="+showAll+"&&result="+paramResult+"&&state="+state
			    								+"&&moduleId="+moduleId+"&&assignId="+assignId+"&&authorId="+authorId
			    			    };
			    				$('#testPlanTable').bootstrapTable('refresh',params);
			    				testPlan_grid.initTestCaseGrid();
		    	        		layer.closeAll();
		    	        		toast.success('操作成功！','成功提示');
		    	        	}else{
		    	        		toast.error('操作失败！','失败提示');
		    	        	}
		    	        }
		    	       });
				 layer.closeAll();
			});
		},
		//修改用例执行状态
		updateTestCaseResult : function(result0){
			var hierarchyIds = "";
			var getSelections = $('#testPlanTable').bootstrapTable('getSelections');
			if(getSelections.length > 0){
				$(getSelections).each(function(index,selection){
					hierarchyIds += hierarchyIds==""?"":",";
					hierarchyIds += selection.hierarchyId;
				});
				$.ajax({
			        type : "post",
			        url : path+'/testCaseController/updateTestCaseResult',//找到controller里相应的方法
			        data : {"hierarchyIds":hierarchyIds,"result":result0}, //把数组的值赋给data，把上面的param改为data,这里就能直接去掉
			        dataType : "json",//根据数据类型选择text、jason等
			        success : function(data) { 
			        	if(data.result == true){
			        		var params={
		    			            silent: true,
		    			            url:path+"/testCaseController/listTestCaseWithResult?nodeId="+nodeId
		    								+"&&showAll="+showAll+"&&result="+paramResult+"&&state="+state
		    								+"&&moduleId="+moduleId+"&&assignId="+assignId+"&&authorId="+authorId
		    			    };
		    				$('#testPlanTable').bootstrapTable('refresh',params);
		    				testPlan_grid.initTestCaseGrid();
			        		toast.success('操作成功！','成功提示');
			        	}else{
			        		toast.error('操作失败！','失败提示');
			        	}
			        }
			       });
			}else{
				toast.info ('请选择您需要处理的信息！','信息提示'); 
			}
		},
		resetTable : function(){
			$('#resultId').val("");
			$('#stateId').val("");
			$('#moduleId').val("");
			$('#assignId').val("");
			$('#authorId').val("");
			paramResult = "";
			state = "";
			moduleId = "";
			assignId = "";
			authorId = "";
			var params={
		            silent: true,
		            url:path+"/testCaseController/listTestCaseWithResult?nodeId="+nodeId
							+"&&showAll="+showAll+"&&result="+paramResult+"&&state="+state
							+"&&moduleId="+moduleId+"&&assignId="+assignId+"&&authorId="+authorId
		    };
			$('#testPlanTable').bootstrapTable('refresh',params);
		}
};
var testPlan_grid = {
		//初始化网格页面
		initTestCaseGrid: function(){
			$.ajax({
		        type: 'get', 
		        url: path+"/testCaseController/listGridTestCaseFromTestPlan?nodeId="+nodeId,
		        dataType:'json',
		        success: function(dataList) {
		        	gloabalGridData = [];
		        	$(dataList).each(function(index,data){
						data["nodeOrder_temp"] = index + 1;
						gloabalGridData.push(data);
					});
		        	//动态拼table
		        	$("#gridBody").html("");
		        	$(gloabalGridData).each(function(caseIndex,caseData){
		        		$("#gridBody").append(
		        				"<tr ondblclick='testPlan_grid.doubleClick();'>"
			        				+"<td onblur='testPlan_grid.loseFocus(this);' class='editable' testcaseId='"+caseData.testcaseId+"' nodeOrder_temp='"+caseData.nodeOrder_temp+"'>"+caseData.name+"</td>"
			        				+"<td class='tdcolor'></td>"
			        				+"<td class='tdcolor'></td>"
		        			+"</tr>"
		        			);
		        		
		        		$(caseData.tcstep).each(function(stepIndex,stepData){
			        		$("#gridBody").append(
			        				 "<tr ondblclick='testPlan_grid.doubleClick();'>"
				        				+"<td class='tdcolor' stepNumber='"+caseData.nodeOrder_temp+"-"+stepData.stepNumber+"'></td>"
				        				+"<td onblur='testPlan_grid.loseFocus(this);' class='editable'>"+stepData.action+"</td>"
				        				+"<td onblur='testPlan_grid.loseFocus(this);' class='editable'>"+stepData.expectedResult+"</td>"
			        			+"</tr>"
			        			);
						});
					});
		        	//网格右键功能
		        	testPlan_grid.gridRightKey();
		        	delCaseList = [];
		        }
		    })
		},
		//在网格最下方添加行
		appendRow : function(){
			//每次新增一个用例之前刷新一次全局变量
        	var trs = document.getElementById('gridBody').getElementsByTagName('tr');
        	var trLen = trs.length;
        	if(trLen == 1 && $(trs[0].getElementsByTagName('td')[0])[0].innerText == ""){
        		toast.info ('网格的开头存在没有关联的测试用例的测试步骤。请为这些测试步骤添加测试用例标题。！','信息提示');
        	}else{
        		for(var i = 0; i < trLen; i++){
    				//获取每个tr中的所有td
    				var oldTds = trs[i].getElementsByTagName('td');
    				//含有新增数据时刷新表格
    				if($(oldTds[0]).attr("testcaseId") == " "){
    					testPlan_grid.refreshGloabalGridData();
                		break;
                	}
    			}
    			if(blankLineFlag == 0){
    				//表格最下方增加一行
    				$("#gridBody").append(
    						"<tr ondblclick='testPlan_grid.doubleClick();'>"
    							+"<td onblur='testPlan_grid.loseFocus(this);' class='editable appendRow'  testcaseId=' ' nodeOrder_temp=' '></td>"
    							+"<td onblur='testPlan_grid.loseFocus(this);' class='editable'></td>"
    							+"<td onblur='testPlan_grid.loseFocus(this);' class='editable'></td>"
    					+"</tr>");
    				//网格右键功能
    				testPlan_grid.gridRightKey();
    			}else{
    				blankLineFlag = 0;
    			}
        	}
		},
		//表格双击事件
		doubleClick: function(){
			//获取点击对象，如果点击对象含有样式editable，则将可编辑设为true，并获取焦点
			var tdHtml = event.srcElement;
			if($(tdHtml).hasClass('editable')){
				$(tdHtml).css("background-color","");
				$(tdHtml).attr("contentEditable","true");
				$(tdHtml).focus();
			}
		},
		//失去焦点触发事件
		loseFocus: function(ele){
			if($(ele).attr("testcaseId")){
				if(ele.innerText.length > 100){
					tooLongFlag = 1;
					$(ele).css({"border":"2px solid #ff00006e","border-top":"2px solid #ff00006e"});
					toast.info ('用例名称不能超过100个字符！','信息提示');
					return false;
				}
			}else{
				if(ele.innerText.length > 255){
					tooLongFlag = 1;
					$(ele).css({"border":"2px solid #ff00006e","border-top":"2px solid #ff00006e"});
					toast.info ('步骤和结果不能超过255个字符！','信息提示');
					return false;
				}
			}
			tooLongFlag = 0;
			$(ele).css({"border":"1px solid #e5e5e5","border-top":"1px solid #e5e5e5"});
			$(ele).attr("contentEditable","false");
			var trHtml = $(ele).parent();
			var tds = trHtml[0].getElementsByTagName('td');
			//当单元格失去焦点时，判断单元格内容是否改变，若有改变则更新数据
			if(!$(tds[0]).hasClass('appendRow') && !$(tds[0]).hasClass('insertRow') && !$(tds[0]).hasClass('insertStepRow')){
				if($(tds[0]).hasClass('editable')){
					var nodeOrder = $(tds[0]).attr("nodeOrder_temp");
					if(tds[0].innerText != gloabalGridData[nodeOrder-1].name){
						gloabalGridData[nodeOrder-1].name = tds[0].innerText;
						if(gloabalGridData[nodeOrder-1].caseFlag == "" || gloabalGridData[nodeOrder-1].caseFlag == null){
							gloabalGridData[nodeOrder-1].caseFlag = "1";
						}
					}
				}else if($(tds[0]).hasClass('tdcolor')){
					var stepNumber = $(tds[0]).attr("stepNumber");
					var str = stepNumber.split("-");
					if(tds[1].innerText != gloabalGridData[str[0]-1].tcstep[str[1]-1].action || tds[2].innerText != gloabalGridData[str[0]-1].tcstep[str[1]-1].expectedResult){
						gloabalGridData[str[0]-1].tcstep[str[1]-1].action = tds[1].innerText;
						gloabalGridData[str[0]-1].tcstep[str[1]-1].expectedResult = tds[2].innerText;
						if(gloabalGridData[str[0]-1].caseFlag == "" || gloabalGridData[str[0]-1].caseFlag == null){
							gloabalGridData[str[0]-1].caseFlag = "1";
							gloabalGridData[str[0]-1].stepFlag = "1";
						}else if(gloabalGridData[str[0]-1].caseFlag == "1"){
							gloabalGridData[str[0]-1].stepFlag = "1";
						}
						
					}
				}
				
			}
		},
		//网格右键功能
		gridRightKey: function(){
			$('#gridBody tr').contextMenu('myMenu1', {
				//菜单项鼠标放在上面样式  
			      itemHoverStyle: {  
			        border: 'none'  
			      },
			          bindings:{  
			            'insert': function(t) {
			            	//每次新增一个用例之前刷新一次全局变量
			            	var trs = document.getElementById('gridBody').getElementsByTagName('tr');
			            	var trLen = trs.length;
			    			for(var i = 0; i < trLen; i++){
			    				//获取每个tr中的所有td
			    				var oldTds = trs[i].getElementsByTagName('td');
			    				if($(oldTds[0]).attr("testcaseId") == " " || $(oldTds[0]).attr("stepnumber") == " "){
			    					testPlan_grid.refreshGloabalGridData();
				            		break;
				            	}
			    			}
			    			//insertRowFlag=0为允许增加一行
			    			if(insertRowFlag == 0){
			    				//获取右击当前行所有的td标签
				            	var tds = t.getElementsByTagName('td');
				            	//如果右击当前行第一个td单元格中含有editable的class，则在其上方增加一行完全可编辑的行，否则只增加步骤列可编辑的行
				            	if($(tds[0]).hasClass('editable')){
				            		//在右击行上方增加一行完全可编辑的行
				            		$(t).before(insertCaseTr);
				            	}else{
				            		$(t).before(insertStepTr);
				            	}
				            	testPlan_grid.gridRightKey();
			    			}else{
			    				insertRowFlag = 0;
			    			}
			            },  
			            'delete': function(t) {
			            	var deleteFlag = 0;
		            		var trs = document.getElementById('gridBody').getElementsByTagName('tr');
		    	        	var trLen = trs.length;
			            	var tds = t.getElementsByTagName('td');
			            	//判断是否有选中行
			            	if($(tds[0]).css("background-color") != "rgb(214, 233, 249)"){
			            		toast.info ('请先选中一行信息！','信息提示');
			            		return false;
			            	}
		   					var slectsTds0 = getSelections[0].getElementsByTagName('td');
			            	var slectsLen = getSelections.length;
			            	//完全可编辑行的删除（新增测试用例在保存之前的删除）
			            	if(slectsLen == 1 && $(slectsTds0[0]).hasClass("editable") && $(slectsTds0[1]).hasClass("editable") && $(slectsTds0[2]).hasClass("editable")){
			            		 layer.confirm('确定要删除选中的信息吗？', {icon: 3, title:'<span class="glyphicon glyphicon-th-large"></span>&nbsp;提示'}, function(){
			            			 $(getSelections[0]).remove();
			    					 layer.closeAll();
			    				});
			            		
			            	}else if(slectsLen == 1 && $(slectsTds0[0]).hasClass('editable') && $(slectsTds0[1]).hasClass('tdcolor') && $(slectsTds0[2]).hasClass('tdcolor')){
			            		//测试用例的删除
			            		 layer.confirm('确定要删除该用例吗？', {icon: 3, title:'<span class="glyphicon glyphicon-th-large"></span>&nbsp;提示'}, function(){
			    					 layer.closeAll();
			    					//获取当前标题行的nodeOrder
					            		var nodeOrder = $(tds[0]).attr("nodeOrder_temp");
					            		//定义记录新增行下一行所在全局变量中索引的变量
						            	var startIndex = nodeOrder;
						            	//在全局变量中找出与testcaseId对应的项，并记录索引值
						            	var caseDataLen = gloabalGridData.length;
					            		//遍历全局变量，并使该右击行及后面所有用例的nodeOrder减1
						            	for(var j = startIndex; j < caseDataLen; j++){
						            		gloabalGridData[j].nodeOrder--;
						            		gloabalGridData[j].nodeOrder_temp--;
						            		gloabalGridData[j].caseFlag = "1";
						            		var stepLen = gloabalGridData[j].tcstep.length;
						            		for(var k = 0; k < stepLen; k++){
						            			gloabalGridData[j].tcstep[k].stepNumber =parseInt(k)+1;
						            		}
						            	}
						            	//将要删除的用例id存入delCaseList中
					            		var testcaseId = gloabalGridData[nodeOrder-1].testcaseId;
					            		delCaseList.push(testcaseId);
					            		gloabalGridData.splice(nodeOrder-1,1);
					            		//页面用例行属性依次发生变化
					    	        	//定义删除该用例开始行变量
					    	        	var beginIdx;
					    	        	//定义用例属性变化开始行变量
					    	        	var beginCaseIdx;
					    				for(var i = 0; i < trLen; i++){
					    					//获取每个tr中的所有td
					    					var newTds0 = trs[i].getElementsByTagName('td');
					    					if($(newTds0[0]).attr("nodeOrder_temp") == nodeOrder){
					    						beginIdx = i;
					    	            		break;
					    	            	}
					    				}
					    				var lastTds1 = trs[trLen-1].getElementsByTagName('td');
					    				
					    				//获取最后一行步骤或者用例所属的nodeOrder
					    				var lastNodeOrderNumber = "";
					    				if($(lastTds1[0]).attr("stepNumber")){
					    					var lastStepNumber = $(lastTds1[0]).attr("stepNumber");
						    				var lastStr = lastStepNumber.split('-');
						    				lastNodeOrderNumber = lastStr[0];
					    				}else{
					    					lastNodeOrderNumber = $(lastTds1[0]).attr("nodeorder_temp");
					    				}
					    				
					    				if(beginIdx == (trLen-1)){//最后一行是没有步骤的用例
					    					beginCaseIdx = beginIdx + 1;
					    				}else{//带有步骤的用例
					    					//确定要删除用例最后一个步骤的索引
						    				for(var j = parseInt(beginIdx) + 1; j < trLen; j++){
												//获取每个tr中的所有td
												var newTds1 = trs[j].getElementsByTagName('td');
												if($(newTds1[0]).hasClass("editable")){
													beginCaseIdx = j;
								            		break;
								            	}else if(lastNodeOrderNumber==nodeOrder){
								            		beginCaseIdx = trLen;
								            		break;
								            	}
											}
					    				}
					    				
					    				for(var k = beginCaseIdx; k < trLen; k++){
					    					//获取每个tr中的所有td
					    					var newTds = trs[k].getElementsByTagName('td');
					    					if($(newTds[0]).hasClass('editable')){
					    						var nodeOrder = $(newTds[0]).attr("nodeOrder_temp");
					    						$(newTds[0]).attr("nodeOrder_temp", parseInt(nodeOrder) - 1);
					    	            	}else if($(newTds[0]).hasClass('tdcolor')){
					    						var stepNumber = $(newTds[0]).attr("stepNumber");
					    						var str = stepNumber.split('-');
					    						$(newTds[0]).attr("stepNumber", parseInt(str[0]) - 1 + "-" + str[1]);
					    	            	}
					    				}
					    				//页面删除选中的用例
					            		for(var l = beginCaseIdx-1; l >= beginIdx; l--){
					    					$(trs[l]).remove();
					    				}
			    				});
			            	}else{
			            		for(var i = 0; i < slectsLen; i++){
				            		var slectsTds = getSelections[i].getElementsByTagName('td');
				            		if($(slectsTds[0]).hasClass('editable')){
				            			toast.info ('含有标题行，无法一起删除！','信息提示'); 
				            			deleteFlag = 1;
				            			break;
				            		}
				            	}
				            	if(deleteFlag == 0){
					            	for(var i = 0; i < trLen; i++){
					    				//获取每个tr中的所有td
					    				var oldTds = trs[i].getElementsByTagName('td');
					    				if($(oldTds[0]).attr("testcaseId") == " "|| $(oldTds[0]).attr("stepnumber") == " "){
					    					testPlan_grid.refreshGloabalGridData();
					                		break;
					                	}
					    			}
				            		layer.confirm('确定要删除选中的信息吗？', {icon: 3, title:'<span class="glyphicon glyphicon-th-large"></span>&nbsp;提示'}, function(){
				            			 layer.closeAll();
				            			//遍历选中要删除的行
										for(var i = 0; i < slectsLen; i++){
											//取出选中的每一条步骤
							            	var currentTds = getSelections[i].getElementsByTagName('td');
											//获取每个选中行的stepNumber属性
					            			var currentStepNumber = $(currentTds[0]).attr("stepNumber");
					            			var currentStr = currentStepNumber.split("-");
					            			//得到所属用例中的所有步骤
											var editSteps = gloabalGridData[currentStr[0]-1].tcstep;
											var editStepsLen = editSteps.length;
											var startStepIdx = parseInt(currentStr[1]);
											//要删除步骤后面的步骤信息stepNumber依次发生变化
											for(var j = startStepIdx; j < editStepsLen; j++){
												var strs = editSteps[j].stepNumber; 
												editSteps[j].stepNumber =parseInt(strs) - 1;
											}
											//从去全局变量中删除一行信息
											gloabalGridData[currentStr[0]-1].tcstep.splice(startStepIdx-1,1);
											//记录标记字段的变化，caseFlag=""为不变，caseFlag="0"为新增，caseFlag="1"为编辑；
											//stepFlag=""为不变，stepFlag="1"为编辑
											if(gloabalGridData[currentStr[0]-1].caseFlag == "" || gloabalGridData[currentStr[0]-1].caseFlag == null){
												gloabalGridData[currentStr[0]-1].caseFlag = "1";
												gloabalGridData[currentStr[0]-1].stepFlag = "1";
											}
											//步骤行依次发生变化
								        	//定义步骤属性变化开始行变量
								        	var beginStepIdx;
								        	//定义步骤属性变化结束行变量
								        	var endStepIdx;
											for(var k = 0; k < trLen; k++){
												//获取每个tr中的所有td
												var newTds1 = trs[k].getElementsByTagName('td');
												if($(newTds1[0]).attr("stepNumber") == currentStepNumber){
													beginStepIdx = k+1;
								            		break;
								            	}
											}
											for(var l =beginStepIdx; l < trLen; l++){
												if(trs[l] == null){
													endStepIdx = l;
													break;
												}else{
													//获取每个tr中的所有td
													var newTds2 = trs[parseInt(l)].getElementsByTagName('td');
													if($(newTds2[0]).hasClass("editable")){
														endStepIdx = l;
									            		break;
									            	}
												}
												
											}
											//当endStepIdx为空时，说明是最后一个用例中的步骤，所以其结束标志为trs的长度
											if(endStepIdx == null){
												endStepIdx = trLen;
											}
											for(var m = beginStepIdx; m < parseInt(endStepIdx); m++){
												//获取每个tr中的所有td
												var newTds3 = trs[m].getElementsByTagName('td');
												var stepNumber = $(newTds3[0]).attr("stepNumber");
												var str = stepNumber.split('-');
												$(newTds3[0]).attr("stepNumber", str[0] + "-" + (parseInt(str[1]) - 1));
											}
					            			$(getSelections[i]).remove();
										}
				            		});
									
				            	}
			            	}
			            },  
			            'clear': function(t) {
			            	var clearFlag = 0;
			            	var trs = document.getElementById('gridBody').getElementsByTagName('tr');
		    	        	var trLen = trs.length;
			            	var tds = t.getElementsByTagName('td');
			            	if($(tds[0]).css("background-color") != "rgb(214, 233, 249)"){
			            		toast.info ('请先选中一行信息！','信息提示');
			            		return false;
			            	}
			            	var slectsTds0 = getSelections[0].getElementsByTagName('td');
			            	var slectsLen = getSelections.length;
			            	
			            	if(slectsLen == 1 && $(slectsTds0[0]).hasClass('editable')){
			            		toast.info ('该行含有标题行，无法清除！','信息提示');
			            	}else{
			            		for(var i = 0; i < slectsLen; i++){
				            		var slectsTds = getSelections[i].getElementsByTagName('td');
				            		if($(slectsTds[0]).hasClass('editable')){
				            			toast.info ('含有标题行，无法一起清除！','信息提示');
				            			clearFlag = 1;
				            			break;
				            		}
				            	}
			            		if(clearFlag == 0){
			            			layer.confirm('确定要清除选中的信息吗？', {icon: 3, title:'<span class="glyphicon glyphicon-th-large"></span>&nbsp;提示'}, function(){
					   					 layer.closeAll();
					   				//遍历选中要清除的行
											for(var i = 0; i < slectsLen; i++){
												//取出选中的每一条步骤
								            	var currentTds = getSelections[i].getElementsByTagName('td');
												//获取每个选中行的stepNumber属性
						            			var currentStepNumber = $(currentTds[0]).attr("stepNumber");
						            			var currentStr = currentStepNumber.split("-");
						            			//得到所属用例中的所有步骤
												var editSteps = gloabalGridData[currentStr[0]-1].tcstep;
												var clearStepIdx = parseInt(currentStr[1])-1;
												//在全局变量中清除该行信息
												editSteps[clearStepIdx].action = "";
												editSteps[clearStepIdx].expectedResult = "";
												//记录标记字段的变化，caseFlag=""为不变，caseFlag="0"为新增，caseFlag="1"为编辑；
												//stepFlag=""为不变，stepFlag="1"为编辑
												if(gloabalGridData[currentStr[0]-1].caseFlag == "" || gloabalGridData[currentStr[0]-1].caseFlag == null){
													gloabalGridData[currentStr[0]-1].caseFlag = "1";
													gloabalGridData[currentStr[0]-1].stepFlag = "1";
												}
												for(var j = 0; j < trLen; j++){
													//获取每个tr中的所有td
													var newTds3 = trs[j].getElementsByTagName('td');
													var stepNumber = $(newTds3[0]).attr("stepNumber");
													if(stepNumber == currentStepNumber){
														$(newTds3[1]).html("");
														$(newTds3[2]).html("");
													}
												}
											}
					   				});
			            		}
			            	}
			            } 
			          }  
		     }); 
		},
		//type ——执行的什么操作，insert、delete、clear、update；tr——操作的该行
		//网格形式的测试步骤右键插入、删除、清除行以及修改标题等操作时 给标题行加上该行变化的属性
		saveGridData: function(){
			testPlan_grid.refreshGloabalGridData();
//			console.log(gloabalGridData.length);
//			for(var i = 0; i < gloabalGridData.length; i++){
//				console.log("newgloabalGridData"+i+": "+JSON.stringify(gloabalGridData[i]));
//			}
			var updateCaseList = [];
			var deleteCase = "";
			$(gloabalGridData).each(function(index,gridData){
				if(gridData.caseFlag != "" && gridData.caseFlag != null){
					updateCaseList.push(gridData);
				}
			});
			var updateCase = JSON.stringify(updateCaseList);
			$(delCaseList).each(function(index,delCase){
				deleteCase += deleteCase ==""?"":",";
				deleteCase += delCase;
			});
			
			var params = {
					"hierarchyId":nodeId,
					"updateCase":updateCase,
					"deleteCase": deleteCase
			};
			if(gloabalGridData.length > 0 || params.updateCase != "[]" || params.deleteCase != ""){
				if(blankLineFlag == 0 && tooLongFlag == 0 && insertRowFlag == 0){
					$.ajax({
		    	        type : "post",
		    	        url :path+'/testCaseController/saveGridTestCaseFromTestPlan',//找到controller里相应的方法
		    	        data : params, //把数组的值赋给data，把上面的param改为data,这里就能直接去掉
		    	        dataType : "json",//根据数据类型选择text、jason等
		    	        success : function(data) { 
		    	        	if(data.result == true){
		    	        		delCaseList = [];
		    	        		testPlan_grid.initTestCaseGrid();
				        		toast.success('操作成功！','成功提示');
				        	}else{
				        		toast.error('操作失败！','失败提示');
				        	}
		    	        }
		    	       });
				}
			}
		},
		gridRefresh : function(){
			testPlan_grid.initTestCaseGrid();
		},
		//更新全局变量
		refreshGloabalGridData: function(){
			//定义区别是否为新增用例的变量
			var insertCaseFlag = 0;
			var insertNoStepFlag = 0;
			//定义区别是否为新增步骤的变量
			var insertStepFlag = 0;
			//是否含有用例粘贴行的标记，0为不含，1为含有；
			var pastFlag = 0;
			//是否含有步骤粘贴行的标记，0为不含，1为含有；
			var stepPastFlag = 0;
			//粘贴的用例是否满足用例行的标记，0为不满足，1为满足；
			var pastCaseFlag = 0;
			//粘贴的步骤是否满足步骤行的标记，0为不满足，1为满足；
			var pastStepFlag = 0;
			//获取表格中的所有数据
			var trs = document.getElementById('gridBody').getElementsByTagName('tr');
			if(trs.length > 0){
				var lastTds = trs[trs.length-1].getElementsByTagName('td');
				//如果含有样式appendRow，则表示为在底部增加一条新的用例，否则需要遍历判断其他情况
				if($(lastTds[0]).hasClass('appendRow')){
					//当tr标签中第一个td的内容不为空时表示新增一个用例，否则表示新增一个步骤
					if(lastTds[0].innerText != ""){
						//当tr标签中第二个或者第三个td的内容不为空时，表示新增用例是同时增加了一个步骤,并将该行数据显示为两行。
						if(lastTds[1].innerText != "" || lastTds[2].innerText != ""){
							var lastNodeOrder;
							if(gloabalGridData.length > 0){//初始化时有数据
								lastNodeOrder = parseInt(gloabalGridData[gloabalGridData.length-1].nodeOrder)+1;
							}else{//初始化时无数据
								lastNodeOrder = 1;
							}
							//在全局变量中增加一条新的用例
			            	gloabalGridData.push({
			            		"testcaseId":"",
			            		"nodeOrder":lastNodeOrder,
			            		"nodeOrder_temp":gloabalGridData.length+1,
			            		"name":lastTds[0].innerText,
			            		"caseFlag":"0",
			            		"stepFlag":"",
			            		"tcstep":[{"tcstepId":"","stepNumber":"1","action":lastTds[1].innerText,"expectedResult":lastTds[2].innerText,"executionType":"","testcaseId":""}]
			            		});
			            		//该行下方扩展一行步骤
								$(trs[trs.length-1]).after("<tr ondblclick='testPlan_grid.doubleClick();'>"
				        				+"<td class='tdcolor' stepNumber='"+gloabalGridData.length+"-1"+"'></td>"
				        				+"<td onblur='testPlan_grid.loseFocus(this);' class='editable'>"+lastTds[1].innerText+"</td>"
				        				+"<td onblur='testPlan_grid.loseFocus(this);' class='editable'>"+lastTds[2].innerText+"</td>"
			        			+"</tr>");
			        			$(lastTds[0]).attr("nodeOrder_temp", gloabalGridData.length);
								testPlan_grid.gridRightKey();
				            	//将该行的步骤与预期结果列置空并置灰
								lastTds[1].innerText = "";
								lastTds[2].innerText = "";
								$(lastTds[1]).addClass('tdcolor');
								$(lastTds[2]).addClass('tdcolor');
								$(lastTds[0]).removeClass('appendRow');
								$(lastTds[1]).removeClass('editable');
								$(lastTds[2]).removeClass('editable');
						}else{
							var lastNodeOrder;
							if(gloabalGridData.length == 0){
								lastNodeOrder = gloabalGridData.length+1;
							}else{
								lastNodeOrder = parseInt(gloabalGridData[gloabalGridData.length-1].nodeOrder)+1;
							}
							//在全局变量中增加一条新的用例
			            	gloabalGridData.push({
			            		"testcaseId":"",
			            		"nodeOrder":lastNodeOrder,
			            		"nodeOrder_temp":gloabalGridData.length+1,
			            		"name":lastTds[0].innerText,
			            		"caseFlag":"0",
			            		"stepFlag":"",
			            		"tcstep":[]
			            		});
							
			        			$(lastTds[0]).attr("nodeOrder_temp", gloabalGridData.length);
								testPlan_grid.gridRightKey();
				            	//将该行的步骤与预期结果列置空并置灰
								$(lastTds[1]).addClass('tdcolor');
								$(lastTds[2]).addClass('tdcolor');
								$(lastTds[0]).removeClass('appendRow');
								$(lastTds[1]).removeClass('editable');
								$(lastTds[2]).removeClass('editable');
						}
					}else{
						if(lastTds[1].innerText != "" || lastTds[2].innerText != ""){
							var gridDataLen = gloabalGridData.length;
							if(gridDataLen == 0){
								toast.info ('网格的开头存在没有关联的测试用例的测试步骤。请为这些测试步骤添加测试用例标题。！','信息提示'); 
							}else if(gridDataLen > 0){
								var stepRow = gloabalGridData[gridDataLen-1].tcstep;
								var stepLen = stepRow.length;
								$(lastTds[0]).addClass('tdcolor');
								stepRow.push({
									"tcstepId":"",
									"stepNumber":parseInt(stepLen)+1,
									"action":lastTds[1].innerText,
									"expectedResult":lastTds[2].innerText,
									"executionType":"",
									"testcaseId":gloabalGridData[gridDataLen-1].testcaseId
									});
								if(gloabalGridData[gridDataLen-1].caseFlag == "" || gloabalGridData[gridDataLen-1].caseFlag == null){
									gloabalGridData[gridDataLen-1].caseFlag = "1";
									gloabalGridData[gridDataLen-1].stepFlag = "1";
								}
								$(lastTds[0]).removeClass('appendRow');
								$(lastTds[0]).removeClass('editable');
								lastTds[0].removeAttribute("testcaseid");
								lastTds[0].removeAttribute("nodeOrder_temp");
								$(lastTds[0]).attr("stepnumber", gridDataLen + "-" + (parseInt(stepLen)+1));
								}
							}else{
								blankLineFlag = 1;
								toast.info ('含有空白行，请先填写信息！','信息提示'); 
							}
						}
				}else{
					//遍历每一个tr
					$(trs).each(function(trIndex,tr){
						var currentNodeOrder;
						//获取每个tr中的所有td
						var tds = tr.getElementsByTagName('td');
						//若class含有insertRow时表示新增元素
						if($(tds[0]).hasClass('insertRow')){
							//获取新增行下一行第一个td单元格中nodeOrder属性的值
							//获取新增行下一行中的所有td
							var nextTds = trs[trIndex+1].getElementsByTagName('td');
		            		var nextNodeOrder = $(nextTds[0]).attr("nodeOrder_temp");
		            		//定义记录新增行下一行所在全局变量中索引的变量
			            	var startIndex = nextNodeOrder-1;
			            	//在全局变量中找出与testcaseId对应的项，并记录索引值
			            	var caseDataLen = gloabalGridData.length;
							//当tr标签中第一个td的内容不为空时表示新增一个用例，否则表示新增一个步骤
							if(tds[0].innerText != ""){
								//当tr标签中第二个或者第三个td的内容不为空时，表示新增用例是同时增加了一个步骤,并将该行数据显示为两行。
								if(tds[1].innerText != "" || tds[2].innerText != ""){
									insertCaseFlag = 1;
						            	//遍历全局变量，并使该右击行及后面所有用例的nodeOrder加1
						            	for(var j = startIndex; j < caseDataLen; j++){
						            		gloabalGridData[j].nodeOrder++;
						            		gloabalGridData[j].nodeOrder_temp++;
						            		gloabalGridData[j].caseFlag = "1";
						            		var stepLen = gloabalGridData[j].tcstep.length;
						            		for(var k = 0; k < stepLen; k++){
						            			gloabalGridData[j].tcstep[k].stepNumber = parseInt(k)+1;
						            		}
						            	}
						            	
						            	//在全局变量中增加一条新的用例
						            	gloabalGridData.push({
						            		"testcaseId":"",
						            		"nodeOrder":gloabalGridData[startIndex].nodeOrder-1,
						            		"nodeOrder_temp":startIndex+1,
						            		"name":tds[0].innerText,
						            		"caseFlag":"0",
						            		"stepFlag":"",
						            		"tcstep":[{"tcstepId":"","stepNumber":"1","action":tds[1].innerText,"expectedResult":tds[2].innerText,"executionType":"","testcaseId":""}]
						            		});
						            	
				            		//记录当前新增行的currentNodeOrder值
				            		currentNodeOrder = startIndex+1;
				            		//该行下方扩展一行步骤
									$(tr).after("<tr ondblclick='testPlan_grid.doubleClick();'>"
					        				+"<td class='tdcolor' stepNumber='"+(parseInt(startIndex)+1)+"-1"+"'></td>"
					        				+"<td onblur='testPlan_grid.loseFocus(this);' class='editable'>"+tds[1].innerText+"</td>"
					        				+"<td onblur='testPlan_grid.loseFocus(this);' class='editable'>"+tds[2].innerText+"</td>"
				        			+"</tr>")
				        			$(tds[0]).attr("nodeOrder_temp", currentNodeOrder);
									testPlan_grid.gridRightKey();
					            	//将该行的步骤与预期结果列置空并置灰
					            	tds[1].innerText = "";
									tds[2].innerText = "";
									$(tds[1]).addClass('tdcolor');
									$(tds[2]).addClass('tdcolor');
									$(tds[1]).removeClass('editable');
									$(tds[2]).removeClass('editable');
									gloabalGridData = testPlan_grid.gloabalGridDataSort(gloabalGridData);
								}else{
									insertCaseFlag = 1;
									insertNoStepFlag = 1;
						            	//遍历全局变量，并使该右击行及后面所有用例的nodeOrder加1
						            	for(var j = startIndex; j < caseDataLen; j++){
						            		gloabalGridData[j].nodeOrder++;
						            		gloabalGridData[j].nodeOrder_temp++;
						            		gloabalGridData[j].caseFlag = "1";
						            		var stepLen = gloabalGridData[j].tcstep.length;
						            		for(var k = 0; k < stepLen; k++){
						            			gloabalGridData[j].tcstep[k].stepNumber = parseInt(k)+1;
						            		}
						            	}
						            	//在全局变量中增加一条新的用例
						            	gloabalGridData.push({
						            		"testcaseId":"",
						            		"nodeOrder":gloabalGridData[startIndex].nodeOrder-1,
						            		"nodeOrder_temp":startIndex+1,
						            		"name":tds[0].innerText,
						            		"caseFlag":"0",
						            		"stepFlag":"",
						            		"tcstep":[]
						            		});
				            		//记录当前新增行的currentNodeOrder值
				            		currentNodeOrder = startIndex+1;
				        			$(tds[0]).attr("nodeOrder_temp", currentNodeOrder);
									testPlan_grid.gridRightKey();
					            	//将该行的步骤与预期结果列置空并置灰
									$(tds[1]).addClass('tdcolor');
									$(tds[2]).addClass('tdcolor');
									$(tds[1]).removeClass('editable');
									$(tds[2]).removeClass('editable');
									gloabalGridData = testPlan_grid.gloabalGridDataSort(gloabalGridData);
								}
							}else{
								if(tds[1].innerText != "" || tds[2].innerText != ""){
									$(tds[0]).addClass('tdcolor');
									var stepRow = gloabalGridData[startIndex-1].tcstep;
									var stepRowLen = stepRow.length;
									stepRow.push({
										"tcstepId":"",
										"stepNumber":parseInt(stepRowLen) + 1,
										"action":tds[1].innerText,
										"expectedResult":tds[2].innerText,
										"executionType":"",
										"testcaseId":gloabalGridData[startIndex-1].testcaseId
										});
									if(gloabalGridData[startIndex-1].caseFlag == "" || gloabalGridData[startIndex-1].caseFlag == null){
										gloabalGridData[startIndex-1].caseFlag = "1";
										gloabalGridData[startIndex-1].stepFlag = "1";
									}
									$(tds[0]).removeClass('insertRow');
									$(tds[0]).removeClass('editable');
									tds[0].removeAttribute("testcaseid");
									tds[0].removeAttribute("nodeOrder_temp");
									$(tds[0]).attr("stepnumber", startIndex + "-" + (parseInt(stepRowLen) + 1));
									}else{
										insertRowFlag = 1;
										toast.info ('含有空白行，请先填写信息！','信息提示');
									}
								}
							}else if($(tds[0]).hasClass('insertStepRow')){
								insertStepFlag = 1;
								//获取新增行下一行中的所有td
								var nextTds = trs[trIndex+1].getElementsByTagName('td');
								//获取新增行下一行第一个td单元格中stepNumber属性的值
			            		var nextStepNumber = $(nextTds[0]).attr("stepNumber");
								var str = nextStepNumber.split('-'); 
								var caseIndex = parseInt(str[0])-1;
								var editSteps = gloabalGridData[caseIndex].tcstep;
								var startStepIdx = parseInt(str[1]) - 1;
								var editStepsLen = editSteps.length;
								for(var i = startStepIdx; i < editStepsLen; i++){
									var strs = editSteps[i].stepNumber; 
									editSteps[i].stepNumber = parseInt(strs) + 1;
								}
								gloabalGridData[caseIndex].tcstep.push(
										{"tcstepId":"","stepNumber":str[1],"action":tds[1].innerText,"expectedResult":tds[2].innerText,"executionType":"","testcaseId":gloabalGridData[caseIndex].testcaseId});
								if(gloabalGridData[caseIndex].caseFlag == "" || gloabalGridData[caseIndex].caseFlag == null){
									gloabalGridData[caseIndex].caseFlag = "1";
									gloabalGridData[caseIndex].stepFlag = "1";
								}
								$(tds[0]).attr("stepNumber", nextStepNumber);
								gloabalGridData[caseIndex].tcstep = testPlan_grid.stepDataSort(gloabalGridData[caseIndex].tcstep);
							}
					});
				}
				
				for(var i = 0; i < trs.length; i++){
					//获取每个tr中的所有td
					var tds = trs[i].getElementsByTagName('td');
					if($(tds[0]).hasClass('pastRow')){
						pastFlag = 1;
						break;
					}
					if($(tds[0]).hasClass('pastStepRow')){
						stepPastFlag = 1;
						break;
					}
				}
				if(pastFlag == 1){
						for(var i = 0; i < trs.length; i++){
							var currentNodeOrder;
							//获取每个tr中的所有td
							var tds = trs[i].getElementsByTagName('td');
							//若class含有pastRow时表示新增元素
							if($(tds[0]).hasClass('pastRow')){
								//获取新增行下一行第一个td单元格中nodeOrder属性的值
								//获取新增行下一行中的所有td
								var startIndex;
								var uperTds = trs[i-1].getElementsByTagName('td');
								if($(uperTds[0]).attr("nodeOrder_temp")){
									var uperNodeOrder = $(uperTds[0]).attr("nodeOrder_temp");
									startIndex = uperNodeOrder;
								}else if($(uperTds[0]).attr("stepnumber")){
									var uperStepNumber = $(uperTds[0]).attr("stepNumber");
									var str = uperStepNumber.split("-");
									startIndex = str[0];
								}
				            	//在全局变量中找出与testcaseId对应的项，并记录索引值
				            	var caseDataLen = gloabalGridData.length;
								//当tr标签中第一个td的内容不为空时表示新增一个用例，否则表示新增一个步骤
								if(tds[0].innerText != ""){
									//当tr标签中第二个或者第三个td的内容不为空时，表示新增用例是同时增加了一个步骤,并将该行数据显示为两行。
									if(tds[1].innerText != "" || tds[2].innerText != ""){
										pastCaseFlag = 1;
							            	//遍历全局变量，并使该右击行及后面所有用例的nodeOrder加1
							            	for(var j = startIndex; j < caseDataLen; j++){
							            		gloabalGridData[parseInt(j)].nodeOrder++;
							            		gloabalGridData[parseInt(j)].nodeOrder_temp++;
							            		gloabalGridData[parseInt(j)].caseFlag = "1";
							            	}
							            	//在全局变量中增加一条新的用例
							            	gloabalGridData.push({
							            		"testcaseId":"",
							            		"nodeOrder":gloabalGridData[startIndex-1].nodeOrder+1,
							            		"nodeOrder_temp":parseInt(startIndex)+1,
							            		"name":tds[0].innerText,
							            		"caseFlag":"0",
							            		"stepFlag":"",
							            		"tcstep":[{"tcstepId":"","stepNumber":"1","action":tds[1].innerText,"expectedResult":tds[2].innerText,"executionType":"","testcaseId":""}]
							            		});
							            	
					            		//记录当前新增行的currentNodeOrder值
					            		currentNodeOrder = parseInt(startIndex)+1;
					            		//该行下方扩展一行步骤
										$(trs[i]).after("<tr ondblclick='testPlan_grid.doubleClick();'>"
						        				+"<td class='tdcolor pastRow' stepNumber='"+(parseInt(startIndex)+1)+"-1"+"'></td>"
						        				+"<td onblur='testPlan_grid.loseFocus(this);' class='editable'>"+tds[1].innerText+"</td>"
						        				+"<td onblur='testPlan_grid.loseFocus(this);' class='editable'>"+tds[2].innerText+"</td>"
					        			+"</tr>")
					        			i++;
					        			$(tds[0]).attr("nodeOrder_temp", currentNodeOrder);
										testPlan_grid.gridRightKey();
						            	//将该行的步骤与预期结果列置空并置灰
						            	tds[1].innerText = "";
										tds[2].innerText = "";
										$(tds[1]).addClass('tdcolor');
										$(tds[2]).addClass('tdcolor');
										$(tds[1]).removeClass('editable');
										$(tds[2]).removeClass('editable');
										gloabalGridData = testPlan_grid.gloabalGridDataSort(gloabalGridData);
									}else{
										pastCaseFlag = 1;
							            	//遍历全局变量，并使该右击行及后面所有用例的nodeOrder加1
							            	for(var j = startIndex; j < caseDataLen; j++){
							            		gloabalGridData[parseInt(j)].nodeOrder++;
							            		gloabalGridData[parseInt(j)].nodeOrder_temp++;
							            		gloabalGridData[parseInt(j)].caseFlag = "1";
							            	}
							            	//在全局变量中增加一条新的用例
							            	gloabalGridData.push({
							            		"testcaseId":"",
							            		"nodeOrder":gloabalGridData[startIndex-1].nodeOrder+1,
							            		"nodeOrder_temp":parseInt(startIndex)+1,
							            		"name":tds[0].innerText,
							            		"caseFlag":"0",
							            		"stepFlag":"",
							            		"tcstep":[]
							            		});
							            	
					            		//记录当前新增行的currentNodeOrder值
					            		currentNodeOrder = parseInt(startIndex)+1;
					        			$(tds[0]).attr("nodeOrder_temp", currentNodeOrder);
										testPlan_grid.gridRightKey();
						            	//将该行的步骤与预期结果列置空并置灰
										$(tds[1]).addClass('tdcolor');
										$(tds[2]).addClass('tdcolor');
										$(tds[1]).removeClass('editable');
										$(tds[2]).removeClass('editable');
										gloabalGridData = testPlan_grid.gloabalGridDataSort(gloabalGridData);
									}
								}else{
										$(tds[0]).addClass('tdcolor');
										var stepRow = gloabalGridData[startIndex-1].tcstep;
										var stepRowLen = stepRow.length;
										stepRow.push({
											"tcstepId":"",
											"stepNumber":parseInt(stepRowLen) + 1,
											"action":tds[1].innerText,
											"expectedResult":tds[2].innerText,
											"executionType":"",
											"testcaseId":gloabalGridData[startIndex-1].testcaseId
											});
										if(gloabalGridData[startIndex-1].caseFlag == "" || gloabalGridData[startIndex-1].caseFlag == null){
											gloabalGridData[startIndex-1].caseFlag = "1";
											gloabalGridData[startIndex-1].stepFlag = "1";
										}
										$(tds[0]).removeClass('editable');
										tds[0].removeAttribute("testcaseid");
										tds[0].removeAttribute("nodeOrder_temp");
										$(tds[0]).attr("stepnumber", startIndex + "-" + (parseInt(stepRowLen) + 1));
									}
						}
					}
					
				
				}
				
				if(stepPastFlag == 1){
					for(var i = 0; i < trs.length; i++){
						//获取每个tr中的所有td
						var tds = trs[i].getElementsByTagName('td');
						//若class含有pastRow时表示新增元素
						if($(tds[0]).hasClass('pastStepRow')){
							pastStepFlag = 1;
							//获取粘贴点击行中的所有td
							var uperTds = trs[i-1].getElementsByTagName('td');
							var caseIndex;
							var startStepIdx;
							//获取粘贴点击行中第一个td单元格中stepNumber属性的值
							if($(uperTds[0]).attr("nodeOrder_temp")){
								var uperNodeOrder = $(uperTds[0]).attr("nodeOrder_temp");
								caseIndex = uperNodeOrder - 1;
								startStepIdx = 0;
							}else if($(uperTds[0]).attr("stepNumber") != " "){
								var uperStepNumber = $(uperTds[0]).attr("stepNumber");
								var str = uperStepNumber.split('-'); 
								caseIndex = parseInt(str[0])-1;
								startStepIdx = parseInt(str[1]);
							}
							var editSteps = gloabalGridData[caseIndex].tcstep;
							
							var editStepsLen = editSteps.length;
							for(var j = startStepIdx; j < editStepsLen; j++){
								var strs = editSteps[j].stepNumber; 
								editSteps[j].stepNumber = parseInt(strs) + 1;
							}
							var nextStepNumber = (parseInt(caseIndex) + 1) + "-" + (parseInt(startStepIdx) + 1);
							gloabalGridData[caseIndex].tcstep.push(
									{"tcstepId":"","stepNumber":parseInt(startStepIdx) + 1,"action":tds[1].innerText,"expectedResult":tds[2].innerText,"executionType":"","testcaseId":gloabalGridData[caseIndex].testcaseId});
							if(gloabalGridData[caseIndex].caseFlag == "" || gloabalGridData[caseIndex].caseFlag == null){
								gloabalGridData[caseIndex].caseFlag = "1";
								gloabalGridData[caseIndex].stepFlag = "1";
							}
							$(tds[0]).attr("stepNumber", nextStepNumber);
							gloabalGridData[caseIndex].tcstep = testPlan_grid.stepDataSort(gloabalGridData[caseIndex].tcstep);
						}
					}
				}
				//当有新插入一条用例时触发,页面行属性排序变化
				if(insertCaseFlag == 1){
					var differLen = 2;
					if(insertNoStepFlag == 1){
						differLen = 1;
					}
					var newTrs = document.getElementById('gridBody').getElementsByTagName('tr');
		        	var newTrLen = newTrs.length;
		        	//定义用例属性变化开始行变量
		        	var beginIdx;
					for(var i = 0; i < newTrLen; i++){
						//获取每个tr中的所有td
						var newTds0 = newTrs[i].getElementsByTagName('td');
						if($(newTds0[0]).hasClass("insertRow")){
							beginIdx = i+differLen;
							$(newTds0[0]).removeClass('insertRow');
		            		break;
		            	}
					}
					for(var j = beginIdx; j < newTrLen; j++){
						//获取每个tr中的所有td
						var newTds = newTrs[j].getElementsByTagName('td');
						if($(newTds[0]).hasClass('editable')){
							var nodeOrder = $(newTds[0]).attr("nodeOrder_temp");
							$(newTds[0]).attr("nodeOrder_temp", parseInt(nodeOrder)+1);
		            	}else if($(newTds[0]).hasClass('tdcolor')){
							var stepNumber = $(newTds[0]).attr("stepNumber");
							var str = stepNumber.split('-');
							$(newTds[0]).attr("stepNumber", parseInt(str[0])+1 + "-" + str[1]);
		            	}
					}
				}
				//当有新插入一条步骤时触发,页面行属性排序变化
				if(insertStepFlag == 1){
					var newTrs1 = document.getElementById('gridBody').getElementsByTagName('tr');
		        	var newTrLen1 = newTrs1.length;
		        	//定义步骤属性变化开始行变量
		        	var beginStepIdx;
		        	//定义步骤属性变化结束行变量
		        	var endStepIdx;
					for(var i = 0; i < newTrLen1; i++){
						//获取每个tr中的所有td
						var newTds1 = newTrs1[i].getElementsByTagName('td');
						if($(newTds1[0]).hasClass("insertStepRow")){
							beginStepIdx = i+1;
							$(newTds1[0]).removeClass('insertStepRow');
		            		break;
		            	}
					}
					for(var j = beginStepIdx; j < newTrLen1; j++){
						//获取每个tr中的所有td
						var newTds2 = newTrs1[j].getElementsByTagName('td');
						if($(newTds2[0]).hasClass("editable")){
							endStepIdx = j;
		            		break;
		            	}
					}
					if(endStepIdx == null){
						endStepIdx = newTrLen1;
					}
					for(var k = beginStepIdx; k < parseInt(endStepIdx); k++){
						//获取每个tr中的所有td
						var newTds3 = newTrs1[k].getElementsByTagName('td');
						var stepNumber = $(newTds3[0]).attr("stepNumber");
						var str = stepNumber.split('-');
						$(newTds3[0]).attr("stepNumber", str[0] + "-" + (parseInt(str[1]) + 1));
					}
				}
				
				if(pastCaseFlag == 1){
					var newTrs = document.getElementById('gridBody').getElementsByTagName('tr');
		        	var newTrLen = newTrs.length;
		        	//定义用例属性变化开始行变量
		        	var beginIdx;
					for(var i = newTrLen - 1; i >= 0; i--){
						//获取每个tr中的所有td
						var newTds0 = newTrs[i].getElementsByTagName('td');
						if($(newTds0[0]).hasClass("pastRow")){
							beginIdx = i+1;
		            		break;
		            	}
					}
					for(var j = beginIdx; j < newTrLen; j++){
						//获取每个tr中的所有td
						var newTds = newTrs[j].getElementsByTagName('td');
						if($(newTds[0]).hasClass('editable')){
							var nodeOrder = $(newTds[0]).attr("nodeOrder_temp");
							$(newTds[0]).attr("nodeOrder_temp", parseInt(nodeOrder)+parseInt(pastRowLen));
		            	}else if($(newTds[0]).hasClass('tdcolor')){
							var stepNumber = $(newTds[0]).attr("stepNumber");
							var str = stepNumber.split('-');
							$(newTds[0]).attr("stepNumber", (parseInt(str[0])+parseInt(pastRowLen)) + "-" + str[1]);
		            	}
					}
					for(var i = 0; i < newTrLen; i++){
						//获取每个tr中的所有td
						var newTds0 = newTrs[i].getElementsByTagName('td');
						if($(newTds0[0]).hasClass("pastRow")){
							$(newTds0[0]).removeClass('pastRow');
		            	}
					}
				}
				if(pastStepFlag == 1){
					var newTrs1 = document.getElementById('gridBody').getElementsByTagName('tr');
		        	var newTrLen1 = newTrs1.length;
		        	//定义步骤属性变化开始行变量
		        	var beginStepIdx;
		        	//定义步骤属性变化结束行变量
		        	var endStepIdx;
		        	for(var i = newTrLen1 - 1; i >= 0; i--){
						//获取每个tr中的所有td
						var newTds0 = newTrs1[i].getElementsByTagName('td');
						if($(newTds0[0]).hasClass("pastStepRow")){
							beginStepIdx = i+1;
		            		break;
		            	}
					}
					for(var j = beginStepIdx; j < newTrLen1; j++){
						//获取每个tr中的所有td
						var newTds2 = newTrs1[j].getElementsByTagName('td');
						if($(newTds2[0]).hasClass("editable")){
							endStepIdx = j;
		            		break;
		            	}
					}
					
					if(endStepIdx == null){
						endStepIdx = newTrLen1;
					}
					for(var k = beginStepIdx; k < parseInt(endStepIdx); k++){
						//获取每个tr中的所有td
						var newTds3 = newTrs1[k].getElementsByTagName('td');
						var stepNumber = $(newTds3[0]).attr("stepNumber");
						var str = stepNumber.split('-');
						$(newTds3[0]).attr("stepNumber", str[0] + "-" + (parseInt(str[1]) + parseInt(pastStepLen)));
					}
					for(var l = 0; l < newTrLen1; l++){
						//获取每个tr中的所有td
						var newTds0 = newTrs1[l].getElementsByTagName('td');
						if($(newTds0[0]).hasClass("pastStepRow")){
							$(newTds0[0]).removeClass('pastStepRow');
		            	}
					}
				}
			}
		},
		//给全局变量按照nodeOrder从小到大排序
		gloabalGridDataSort: function(data){
				   var len = data.length;
				   var minIndex, temp;
				   for (var i = 0; i < len - 1; i++) {
				       minIndex = i;
				       for (var j = i + 1; j < len; j++) {
				           if (data[j].nodeOrder < data[minIndex].nodeOrder) {     // 寻找最小的数
				               minIndex = j;                 // 将最小数的索引保存
				           }
				       }
				       temp = data[i];
				       data[i] = data[minIndex];
				       data[minIndex] = temp;
				   }
				   return data;
		},
		//将步骤按照stepNumber从小到大排序
		stepDataSort: function(data){
			 var len = data.length;
			   var minIndex, temp;
			   for (var i = 0; i < len - 1; i++) {
			       minIndex = i;
			       for (var j = i + 1; j < len; j++) {
			    	   var str0 = data[minIndex].stepNumber;
			    	   var str = data[j].stepNumber;
			           if (parseInt(str) < parseInt(str0)) {     // 寻找最小的数
			               minIndex = j;                 // 将最小数的索引保存
			           }
			       }
			       temp = data[i];
			       data[i] = data[minIndex];
			       data[minIndex] = temp;
			   }
			   return data;
		},
		//点击获得行tr
		doclick: function (){
			// 通过event.srcelement 获取激活事件的对象   
			var ele = event.srcElement; 
			var trHtml = $(ele).parent();
			//当ctrl和shift键都未按下时触发
			if (shiftKey == false && ctrlKey == false){
				getSelections = [];
				getSelections.push(trHtml[0]);
			}
			//获取并遍历当前状态的所有tr
			var trs = document.getElementById('gridBody').getElementsByTagName('tr');
			var trsLen = trs.length;
			//当shift键按下时触发
			if (shiftKey == true){
				var firstRow = getSelections[0];
				//获取按下shift键时的第一条和最后一条数据
				var firstRowTds = firstRow.getElementsByTagName('td');
				var lastRowTds = trHtml[0].getElementsByTagName('td');
					var slectsLen = getSelections.length;
					getSelections.splice(1,slectsLen-1);
					var firstIndex;
					var lastIndex;
					//判断第一条数据是否为标题行，若是，则获取nodeOrder属性，否则，获取stepNumber属性
					if($(firstRowTds[0]).hasClass("editable")){
						var firstNodeOrder = $(firstRowTds[0]).attr("nodeOrder_temp");
						for(var i = 0; i < trsLen; i++){
							var tds = trs[i].getElementsByTagName('td');
							if($(tds[0]).attr("nodeOrder_temp") == firstNodeOrder){
								firstIndex = i;
							}
						}
					}else if($(firstRowTds[0]).hasClass("tdcolor")){
						var firstStepNumber = $(firstRowTds[0]).attr("stepNumber");
						for(var i = 0; i < trsLen; i++){
							var tds = trs[i].getElementsByTagName('td');
							if($(tds[0]).attr("stepNumber") == firstStepNumber){
								firstIndex = i;
							}
						}
					}
					//判断最后一条数据是否为标题行，若是，则获取nodeOrder属性，否则，获取stepNumber属性
					if($(lastRowTds[0]).hasClass("editable")){
						var lastNodeOrder = $(lastRowTds[0]).attr("nodeOrder_temp");
						for(var i = 0; i < trsLen; i++){
							var tds = trs[i].getElementsByTagName('td');
							if($(tds[0]).attr("nodeOrder_temp") == lastNodeOrder){
								lastIndex = i;
							}
						}
					}else if($(lastRowTds[0]).hasClass("tdcolor")){
						var lastStepNumber = $(lastRowTds[0]).attr("stepNumber");
						for(var i = 0; i < trsLen; i++){
							var tds = trs[i].getElementsByTagName('td');
							if($(tds[0]).attr("stepNumber") == lastStepNumber){
								lastIndex = i;
							}
						}
					}
					//将选中的第二条数据到最后一条数据保存到getSelections数组中
					for(var j = firstIndex+1; j <= lastIndex; j++){
						getSelections.push(trs[j]);
					}
					//依次将改变选中的数据行颜色
					for(var k = 0; k < trsLen; k++){
						//判断trs中的数据是否在getSelections数组中，若在则改变行颜色，否则不改变行颜色
						if (getSelections.indexOf(trs[k]) > -1){
							var tds = trs[k].getElementsByTagName('td');
							$(tds).each(function(tdIndex,td){
								$(td).css("background-color","#d6e9f9");
							});
						}else{
							var tds1 = trs[k].getElementsByTagName('td');
							$(tds1).each(function(tdIndex,td){
								$(td).css("background-color","");
							});
						}
					}
			}else if(ctrlKey == true){//当ctrl键按下时触发
				var pushFlag = 0;
				//获取当前点击的行，并将当前行当做getSelections中的下一条数据存入数组中
					var nextRow = trHtml[0];
					$(getSelections).each(function(selectIdx,selection){
						if(selection == trHtml[0]){
							pushFlag = 1;
							getSelections.splice(selectIdx,1);
						}
					});
					if(pushFlag == 0){
						getSelections.push(nextRow);
					}
					//遍历trs数组，并改变选中行的颜色
					$(trs).each(function(trIndex,tr){
						//获取每个tr标签中所有td
						var tds = tr.getElementsByTagName('td');
						//如果tr单元项与当前点击行相同，则处于选中状态，否则处于非选中状态
						if(tr == trHtml[0]){
							if($(tds[0]).css("background-color") == "rgb(214, 233, 249)"){
								$(tds).each(function(tdIndex,td){
									$(td).css("background-color","");
								});
							}else{
								$(tds).each(function(tdIndex,td){
									$(td).css("background-color","#d6e9f9");
								});
							}
						}
					});
			}else{
				$(trs).each(function(trIndex,tr){
					//获取每个tr标签中所有td
					var tds = tr.getElementsByTagName('td');
					//如果tr单元项与当前点击行相同，则处于选中状态，否则处于非选中状态
					if(tr == trHtml[0]){
						$(tds).each(function(tdIndex,td){
							$(td).css("background-color","#d6e9f9");
						});
					}else{
						$(tds).each(function(tdIndex,td){
							$(td).css("background-color","");
						});
					}
				});
			}
		},
		//判断浏览器类型
		myBrowser: function(){
			var userAgent = navigator.userAgent; //取得浏览器的userAgent字符串
		    if (userAgent.indexOf("Chrome") > -1){
			  return "Chrome";
			 }
		   if(window.ActiveXObject || "ActiveXObject" in window){
		    	return "IE";
		    }
		},
		//IE、chrome浏览器共用粘贴方法
		traverseExeclTr: function(trs){
			pastStepLen = trs.length;
			//定义列标志
			var colFlag;
			//记录点击行下一行的索引
			var nextIndex;
			//获取当前点击对象
			var ele = event.srcElement;
			//获取当前点击对象的stepNumber属性
			var stepNumber = $(ele).attr("stepNumber");
			
			//获取点击对象所属的tr
			var trHtml = $(ele).parent();
			//获取点击对象所属tr中的所有td
			var tdsHtml = trHtml[0].getElementsByTagName('td');
			//每次新增一个用例之前刷新一次全局变量
        	var oldtrs = document.getElementById('gridBody').getElementsByTagName('tr');
        	var trLen = oldtrs.length;
			//取出当前全部trs的最后一个tr对应的全部td
			var lastTds = oldtrs[trLen-1].getElementsByTagName('td');
			var nextTds;
			for(var i = 0; i < trLen; i++){
				//获取每个tr中的所有td
				var oldTds = oldtrs[i].getElementsByTagName('td');
				if($(oldTds[0]).attr("testcaseId") == " "){
					testPlan_grid.refreshGloabalGridData();
            		break;
            	}
			}
			//获取点击对象所在的列
			for(var i = 0; i < tdsHtml.length; i++){
				if(tdsHtml[i] == ele){
					colFlag = i + 1;
				}
			}
			if(colFlag == 1){
				//当点击对象不在最后一行的第一列时触发
				if(lastTds[0] != ele){
					//当点击对象在第一列，并且含有tdcolor时，记录其下一行的索引
					if($(ele).hasClass("tdcolor")){
						for(var i = 0; i < trLen; i++){
							var tds0 = oldtrs[i].getElementsByTagName('td');
							if($(tds0[0]).attr("stepNumber") == stepNumber){
								nextIndex = i+1;
							}
						}
					}else if($(ele).attr("nodeorder_temp")){//当点击对象在第一列，并且是用例标题时，记录其下一行的索引
						//获取当前点击对象的nodeorder_temp属性
						var nodeorder_temp = $(ele).attr("nodeorder_temp");
						for(var i = 0; i < trLen; i++){
							var tds0 = oldtrs[i].getElementsByTagName('td');
							if($(tds0[0]).attr("nodeorder_temp") == nodeorder_temp){
								nextIndex = i+1;
							}
						}
					}
					//如果下一行的索引不为空，则获取其下一行对应的全部tds
					if(nextIndex != null){
						nextTds = oldtrs[nextIndex].getElementsByTagName('td');
					}
				}
				//点击对象为第一列且下方有editable，或者在点击对象为最后一行，则可以粘贴用例
				if(lastTds[0] == ele || $(nextTds[0]).hasClass("editable")){
					var trsLen = trs.length;
					var caseNum = 0;
					for(var i = 0; i < trsLen; i++){
						var tds = trs[i].getElementsByTagName('td');
						if(tds[0].innerText != ""){
							caseNum++;
						}
					}
					pastRowLen = caseNum;
					var firstTds = trs[0].getElementsByTagName('td');
					var afterTrs = "";
					if(firstTds.length == 0){
						toast.info ('粘贴内容为空！','信息提示');
					}else if(firstTds.length == 1){
						$(trs).each(function(trIndex,tr){
							var tds = tr.getElementsByTagName('td');
							afterTrs += "<tr ondblclick='testPlan_grid.doubleClick();'>"
							    +"<td onblur='testPlan_grid.loseFocus(this);' class='editable pastRow' testcaseId=' ' nodeOrder_temp=' '>" + tds[0].innerText + "</td>"
							    +"<td onblur='testPlan_grid.loseFocus(this);' class='editable'></td>"
							    +"<td onblur='testPlan_grid.loseFocus(this);' class='editable'></td>"
							+"</tr>"
						});
					}else if(firstTds.length == 2){
						$(trs).each(function(trIndex,tr){
							var tds = tr.getElementsByTagName('td');
							afterTrs += "<tr ondblclick='testPlan_grid.doubleClick();'>"
							    +"<td onblur='testPlan_grid.loseFocus(this);' class='editable pastRow' testcaseId=' ' nodeOrder_temp=' '>" + tds[0].innerText + "</td>"
							    +"<td onblur='testPlan_grid.loseFocus(this);' class='editable'>" + tds[1].innerText + "</td>"
							    +"<td onblur='testPlan_grid.loseFocus(this);' class='editable'></td>"
							+"</tr>"
						});
					}else if(firstTds.length == 3){
						$(trs).each(function(trIndex,tr){
							var tds = tr.getElementsByTagName('td');
							afterTrs += "<tr ondblclick='testPlan_grid.doubleClick();'>"
							    +"<td onblur='testPlan_grid.loseFocus(this);' class='editable pastRow' testcaseId=' ' nodeOrder_temp=' '>" + tds[0].innerText + "</td>"
							    +"<td onblur='testPlan_grid.loseFocus(this);' class='editable'>" + tds[1].innerText + "</td>"
							    +"<td onblur='testPlan_grid.loseFocus(this);' class='editable'>" + tds[2].innerText + "</td>"
							+"</tr>"
						});
					}else if(firstTds.length > 3){
						toast.info ('粘贴的数据列过大，最多允许三列！','信息提示');
					}
					$(trHtml[0]).after(afterTrs);
					testPlan_grid.gridRightKey();
				}else{
					toast.info ('标题行只能粘贴到测试用例末尾，而不能粘贴在测试步骤之间！','信息提示');
				}
			}else if(colFlag == 2){
				var firstTds = trs[0].getElementsByTagName('td');
				var afterStepTrs = "";
				if(firstTds.length == 0){
					toast.info ('粘贴内容为空！','信息提示');
				}else if(firstTds.length == 1){
					$(trs).each(function(trIndex,tr){
						var tds = tr.getElementsByTagName('td');
						afterStepTrs += "<tr ondblclick='testPlan_grid.doubleClick();'>"
							+"<td class='tdcolor pastStepRow' stepNumber=' '></td>"
							+"<td onblur='testPlan_grid.loseFocus(this);' class='editable'>" + tds[0].innerText + "</td>"
							+"<td onblur='testPlan_grid.loseFocus(this);' class='editable'></td>"
					    +"</tr>"
					});
				}else if(firstTds.length == 2){
					$(trs).each(function(trIndex,tr){
						var tds = tr.getElementsByTagName('td');
						afterStepTrs += "<tr ondblclick='testPlan_grid.doubleClick();'>"
							+"<td class='tdcolor pastStepRow' stepNumber=' '></td>"
							+"<td onblur='testPlan_grid.loseFocus(this);' class='editable'>" + tds[0].innerText + "</td>"
							+"<td onblur='testPlan_grid.loseFocus(this);' class='editable'>" + tds[1].innerText + "</td>"
					    +"</tr>"
					});
				}else if(firstTds.length > 2){
					toast.info ('粘贴的数据列过大！','信息提示'); 
				}
				$(trHtml[0]).after(afterStepTrs);
				testPlan_grid.gridRightKey();
			}else if(colFlag == 3){
				var firstTds = trs[0].getElementsByTagName('td');
				var afterStepTrs = "";
				if(firstTds.length == 0){
					toast.info ('粘贴内容为空！','信息提示');
				}else if(firstTds.length == 1){
					$(trs).each(function(trIndex,tr){
						var tds = tr.getElementsByTagName('td');
						afterStepTrs += "<tr ondblclick='testPlan_grid.doubleClick();'>"
							+"<td class='tdcolor pastStepRow' stepNumber=' '></td>"
							+"<td onblur='testPlan_grid.loseFocus(this);' class='editable'></td>"
							+"<td onblur='testPlan_grid.loseFocus(this);' class='editable'>" + tds[0].innerText + "</td>"
					    +"</tr>"
					});
				}else if(firstTds.length > 1){
					toast.info ('粘贴的数据列过大！','信息提示'); 
				}
				$(trHtml[0]).after(afterStepTrs);
				testPlan_grid.gridRightKey();
			}
		}
}



